import requests
"""
做接口测试用的测试库
"""
# 发起一个请求
"""
url：请求地址
协议：HTTP/HTTPS
端口号
请求方式：POST、GET、DELETE、PUT
请求参数：json、form表单
请求头参数：content-type、token鉴权
"""
# 发起登录接口
response = requests.post("http://47.99.66.20:8899/adminapi/login",json={"account":"admin","pwd":"123456","key":"68c7c0130fd05","captchaType":"blockPuzzle","captchaVerification":""})
# 打印响应状态码
# print(response.status_code)
# 打印响应体，是文本格式，字符串
# print(response.text)
# 打印响应体，是字典格式的
token = response.json()['data']['token']
# print(response.json())
# print(response.json()['data']['menus'][0]['path'])
# print(response.json()['menus']['id'])
# result = {"name":"suki","address":[{'name':"shanghai",'qihou':"re"},{"name":"shenyang",'qihou':"leng"}]}
# print(result['address'][1]['name'])
"""
def aaa():
    return {"name":"suki"}
print(aaa()['name'])
"""
# 用户分组查询
response = requests.get("http://47.99.66.20:8899/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-zation":"Bearer "+str(token)})
# 打印响应
# print(response.json())
# 循环遍历，找到：lalalal112的id值
for i in response.json()['data']['list']:
    # 第一次循环，i的值是：{'id': 13, 'group_name': '小白测试接口1231'}
    # 第二次循环，i的值是：{'id': 18, 'group_name': '1111866225'}
    if i['group_name'] == "lalalal112":
        print(i['id'])
